how to use the id selector in html and css
Syntax of HTML <id> tag
<element id="nuiquename">
.. content
.
</element>
- Attribute provide additional information about element
- id attribute unique on entire webpage
- id attribute name cannot start with number.
- id attribute name cannot space allowed.
- id attribute name no allowed space and use - or _ symbols
how to use the id selector in html and css
Example
<!DOCTYPE html>
<html>
<head>
<style>
#header{
color: black;
}
</style>
</head>
<body>
<h2 id="header"> HTML id Attribute</h2>
<p> HTML id attribute use unique name on webpage </p>
</body>
</html>
how to use the id selector in html and css
Explain Program
Step 1]
<!DOCTYPE html>
- This declare the document type.
- browser that the document is written in html
Step 2 ]
<html>.... . </html>
- html is the root element of the html page.
- Every thing inside it is part of the webpage.
Step 3]
<head>
<style>
#header{
background-color: lightblue;
color: black;
text-align: center;
padding: 20px;
}
</style>
</head>
- <head> section
- head section contains metadata about page. not visible on the page itself.
- <title> tag title section set the title of the page shows the browser tab.
2. CSS Style
- #header { . . . }
- # symbol represent selecting id element .
- #header :- HTML element .
- background-color :- set the background color.
- color :- set text color.
- text-align : center :- text center element.
- padding: 20px :- 20 pixels of space inside element. (top, bottom, right, left)
Step 4]
<body>
- < body> tag contains all the content visible to webpage.
- <body> tag contains all the visible content of the page.
- inside <body> show the browser screen.
Step 5]
<body>
<h2 id="header"> HTML id Attribute</h2>
<p> HTML id attribute use unique name on webpage </p>
</body>
- <h2> :- heading tag .
- <id="header"> :- unique identifier name
- CSS <style> :- section style element id.
header id attribute appears
- background -color
- color
- text-align
- padding
Step 6]
closing the Tag
</body>
</html>
