HTML styles refer to the methods used to define the visual presentation of HTML elements on a web page. While HTML primarily focuses on structuring content, styles (typically implemented with CSS) control how that content appears, including aspects like colors, fonts, sizes, spacing, and layout.
There are three main ways to apply styles in HTML:
- Inline Styles: These are applied directly to individual HTML elements using the
styleattribute. This method allows you to set specific CSS properties and values for a single element.
Code
<p style="color: blue; font-size: 16px;">This text is blue and 16px.</p>
- Internal Styles: These are defined within a
<style>tag placed in the<head>section of an HTML document. This allows you to define styles for multiple elements within that specific HTML document.
Code
<head> <style> h1 { color: red; text-align: center; } p { font-family: Arial, sans-serif; } </style> </head>
- External Stylesheets: This is the most recommended and common method for styling web pages. Styles are defined in a separate
.cssfile and linked to the HTML document using the<link>tag in the<head>section. This allows for consistent styling across multiple HTML pages and easier maintenance.
Code
<head> <link rel="stylesheet" href="styles.css"> </head>
(And in
styles.css file):Code
body { background-color: powderblue; } h1 { color: navy; }
In essence, HTML styles, powered by CSS, provide the means to transform raw, structured content into visually appealing and user-friendly web pages.
