To apply CSS styles to your HTML documents, you can use one of the following methods:
Inline CSS: Add styles directly to an HTML element using the
styleattribute.<h1 style="color: blue; text-align: center;">Hello World</h1>Internal CSS: Include a
<style>tag within the<head>section of your HTML document.<head> <style> body { background-color: lightgray; } h1 { color: green; } </style> </head>External CSS: Create a separate CSS file (e.g.,
style.css) and link it to your HTML document.<head> <link rel="stylesheet" href="style.css" /> </head>In
style.css, you can write your CSS rules:body { background-color: lightgray; } h1 { color: green; }
Choose the method that best fits your project needs. External CSS is generally preferred for larger projects as it keeps your HTML clean and separates content from presentation.
