The <style> tag is used to define internal CSS styles for an HTML document. This tag allows you to apply styling rules directly within the <head> section, affecting elements on the same page.
While external stylesheets (using <link>) are preferred for larger projects, the <style> tag is useful for small internal styles or quick tests.
<style>
selector {
property: value;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #f0f0f0;
}
h1 {
color: darkblue;
font-size: 32px;
}
p {
font-size: 18px;
}
</style>
<title>Style Tag Example</title>
</head>
<body>
<h1>Styled Page</h1>
<p>This paragraph is styled using internal CSS.</p>
</body>
</html>
The <style> tag gives you the ability to apply CSS styles directly within your HTML document. For larger websites, it's better to use external stylesheets, but <style> is great for quick and localized styling.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!