html span and div tags | div tag and span tag in html #html #htmlcss
HTML SPAN TAG
Here's an example of how the <span> tag can be used:
<p>This is a <span style="color: blue;">blue</span> text.</p>
In the example above, the word "blue" is wrapped in a <span> tag with a style attribute that sets the color to blue. This allows you to apply specific styles to that particular portion of the text.
Alternatively, you can also apply a class or ID to the <span> tag and define the styles in an external CSS file or using a <style> block. Here's an example
<style>
.highlight {
background-color: yellow;
font-weight: bold;
}
</style>
<p>This is a <span class="highlight">highlighted</span> text.</p>
In this case, the <span> element has a class attribute of "highlight," and the corresponding CSS styles define a yellow background color and bold font weight.
HTML DIV TAG
The <div> tag in HTML is a block-level element that is used to create a division or a container for grouping and organizing other HTML elements. It is a versatile and commonly used element for creating layouts and applying styles.
Here's an example of how the <div> tag can be used:
<div>
<h1>Welcome to my website!</h1>
<p>This is some content inside a div.</p>
<img src="image.jpg" alt="An image">
</div>
In the example above, the <div> element is used to group the heading (<h1>), paragraph (<p>), and image (<img>) elements together. The contents within the <div> will be treated as a separate block, allowing you to apply styles or manipulate them as a unit.
You can also assign classes or IDs to <div> elements for more targeted styling or scripting:
<div class="container" id="main-content">
<!-- Content goes here -->
</div>
In this case, the <div> element has a class attribute of "container" and an ID attribute of "main-content." These attributes can be used to reference the element in CSS or JavaScript code, allowing you to apply specific styles or perform actions on that particular <div>.
The <div> tag is an essential building block in HTML layouts and is often used in conjunction with CSS to create complex designs and structures on web pages.
Comments
Post a Comment