HTML defines the content and structure of a web page, while styles control how that content looks. With the help of CSS (Cascading Style Sheets), you can change colors, fonts, spacing, and layout. Styles can be added inline (inside tags), internally (inside a <style> block), or using an external CSS file. In this topic, we focus on inline and internal styles.
style attribute inside an HTML tag.<style> tag in the <head> section.selector { property: value; } (e.g., color: red;).color, background-color, font-size, font-family, padding, margin.CSS targets HTML elements using selectors. Each selector has one or more properties with values:
selector { property: value; }
For example, to style all <h1> elements:
h1 { color: blue; font-size: 32px; }
Inline styles override internal and external styles for that specific element, but they quickly become messy if overused. Internal styles (inside <style>) allow you to style many elements at once in the same file.
The following example shows both inline and internal styling working together:
<!-- Simple example using both inline and internal styles -->
<!DOCTYPE html>
<html>
<head>
<title>Styled Page Example</title>
<style>
/* Internal styles applied to the whole page */
body {
background-color: #f0f8ff; /* Light blue background */
font-family: Arial, sans-serif; /* Readable font */
}
h2 {
color: #2a52be; /* Subheading color */
}
p.intro {
font-size: 18px; /* Larger paragraph font */
color: #333333; /* Dark text */
}
</style>
</head>
<body>
<h1 style="color: darkred;">Welcome to HTML Styles!</h1> <!-- Inline style for heading -->
<p class="intro">This paragraph uses internal styling with a class.</p>
<p style="font-weight: bold; background-color: #ffffcc;">
This paragraph uses inline styling to appear bold with a yellow background.
</p>
</body>
</html>
This paragraph uses internal styling with a class.
This paragraph uses inline styling to appear bold with a yellow background.
Here, the page background and font family are controlled by internal CSS, while some headings and paragraphs use inline styles for quick, element-specific changes.
.intro or .highlight instead of .style1.font-size, margin, and padding to see how spacing changes..note and apply it to a paragraph to highlight important text.HTML styles, powered by CSS, control the visual presentation of your web pages. You learned how to add styles using inline and internal methods, how CSS syntax works, and how properties like color and font-size change the appearance of elements. As your projects grow, you’ll rely more on internal and external stylesheets to keep design consistent and your code clean.