There are three main ways to apply styles to HTML:
- Inline — using the
styleattribute directly on an element. - Internal — using a
<style>block inside the page’s<head>. - External — using a separate
.cssfile linked via<link>.
There are three main ways to apply styles to HTML:
style attribute directly on an element.<style> block inside the page’s <head>..css file linked via <link>.Best Practice: Prefer external CSS for real projects (cleaner HTML, reusable styles, better performance). Use inline styles only for quick tests or very small overrides.
<h2 style="color: blue; text-align: center;">Inline Styled Heading</h2>
<p style="font-size: 18px; color: #333;">
This paragraph uses inline CSS with multiple properties.
</p>
<head>
<style>
h1 { color: #e11d48; text-transform: uppercase; }
.card { border: 1px solid #ddd; padding: 12px; border-radius: 6px; }
</style>
</head>
<head>
<link rel="stylesheet" href="styles.css">
</head>
Create a file named styles.css and place all your CSS rules there.
color, background-colorfont-size, font-family, font-weighttext-align, text-transform, text-decorationmargin, padding, border, border-radiuswidth, height, display
<p style="color: red;">Named color (red)</p>
<p style="color: #16a34a;">HEX color (#16a34a)</p>
<p style="color: rgb(59,130,246);">RGB color (59,130,246)</p>
This paragraph uses inline CSS with multiple properties.
In real projects, move these rules into <style> or a .css file.
Named color (red)
HEX color (#16a34a)
RGB color (59,130,246)
Tip: When using multiple CSS sources, the browser applies the cascade:
Inline > Internal > External (unless overridden with !important).