0% completed
CSS ID selectors let you style a unique element on your web page. They are used by adding an id attribute to an HTML element. An ID selector applies styles only to the element with the matching id value. This method is useful when you want to style a single item differently from the rest of the page.
Unlike class selectors, ID selectors should be unique within a page, which means you should use an id only once per HTML document.
Follow below syntax to add an ID selector in CSS code.
#selector { property: value; }
Explanation:
id attribute.In this example, we will style an element with a unique id called unique-header. The example changes the text color and adds extra space below the element.
Explanation:
#unique-header:
id="unique-header".<h1> element with the specified ID will receive the styles.In this example, we will demonstrate how an ID selector can be used alongside element selectors. The ID is used to style a unique paragraph differently than other paragraphs on the page.
Explanation:
p element targets all paragraphs.#special-paragraph:
#special-paragraph applies only to the paragraph with that ID.This lesson shows how to use ID selectors to target a specific element. You now understand how to apply unique styles to HTML elements using their id attribute.
.....
.....
.....