To select elements based on their position, you can use the <InlineCode>[position()]</InlineCode> or <InlineCode>[last()]</InlineCode> syntax. For example, to select the first <p> element in an HTML document, you can use the XPath expression //p[position()=1].