Semantic HTML elements
These semantic elements simply mean, elements with meaning. The reason being, there definition in the code tells the browser and the developer what they are supposed to do. Framing in simpler words, these elements describe the type of content they are supposed to contain.
Following is the list of some semantic elements:
- article
- aside
- details
- figcaption
- figure
- footer
- form
- header
- main
- mark
- nav
- table
- section
Example: This example shows the use of semantic elements.
<!DOCTYPE html>
<html>
<head>
<title>my web page</title>
<style type="text/css">
h1 {
color: green;
font-weight: bold;
}
table,
tr,
td {
border: 1px solid black;
}
th {
font-weight: bold;
color: red;
}
</style>
</head>
<body>
<article>
<h1>GeeksforGeeks</h1>
<p>A Computer Science Portal for Geeks</p>
</article>
<table>
<tr>
<th>head1</th>
<th>head2</th>
</tr>
<tr>
<td>A</td>
<td>0</td>
</tr>
<tr>
<td>B</td>
<td>1</td>
</tr>
</table>
</body>
</html>
Non-Semantic elements
Unlike, semantic elements they don't have any meaning. They don't tell anything about the content they contain. They can be used with different attributes to mark up semantics common to a group.
Following is the list of some non-semantic elements:
- div
- span
Example: This example shows the use of non-semantic elements.
<!DOCTYPE html>
<html>
<head>
<title>my web page</title>
<style type="text/css">
span {
color: green;
font-size: 40px;
font-weight: bold;
}
</style>
</head>
<body>
<div>
<span>GeeksForGeeks</span> <br>
A computer science portal for geeks
</div>
</body>
</html>
Difference between semantic and non-semantic elements
Semantic elements Non-Semantic elements
They have meaning They don't have meaning
They describe how the content within them is supposed to behave They can contain anything
They have specific attributes for their structure The 'class' attribute can be used to work with their structure
Reference: https://www.geeksforgeeks.org/html/difference-between-semantic-and-non-semantic-elements/
Top comments (2)
Please refer at least 3 to 4 websites.
ok sir