HTML Styles

In HTML, you can apply styles to your elements using inline styles or external style sheets. Here's a brief explanation of both approaches:


1. Inline Styles:

Inline styles are applied directly to individual HTML elements using the `style` attribute. You can specify various CSS properties within this attribute to define the styling for that particular element. Here's an example of how to use inline styles:

html
<p style="color: red; font-size: 16px;">This is a red paragraph with font size 16 pixels.</p>

In the above example, the `style` attribute is added to the `<p>` element to set its text color to red and font size to 16 pixels.


2. External Style Sheets:

External style sheets allow you to define styles in a separate CSS file and link it to your HTML document. This approach is useful when you have multiple HTML pages that need to share the same styling rules. Here's how you can use an external style sheet:


HTML file (index.html):
html
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
    <p>This is a paragraph.</p>
</body>
</html>

CSS file (styles.css):
css
p {
    color: red;
    font-size: 16px;
}

In the above example, the `<link>` tag within the `<head>` section is used to link the external style sheet (styles.css) to the HTML file. The CSS file contains the styling rules for the `<p>` element, setting its color to red and font size to 16 pixels.

Remember to replace the file paths (e.g., "styles.css") with the correct paths to your CSS file if you're using external style sheets.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext