Chapter 3, Episode 2: Inline CSS Basics
CodyMcTweak
Hey everyone! Our student has built their first HTML page from the previous chapters, but... well... it's kind of plain. Take a look:
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Page</h1>
<p>This is a paragraph about me. I like coding and learning new things.</p>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</body>
</html>
Welcome to My Page
This is a paragraph about me. I like coding and learning new things.
- HTML
- CSS
- JavaScript
TrashyMcTweak
What the actual GARBAGE is this?! This webpage looks like it was designed during the Stone Age! No colors? No style? It's like serving a plain rice cake and calling it gourmet cuisine! We need to give this digital eyesore some flair before I throw my circuits into a blender!
AllyMcTweak
Let's not be too harsh, Trashy. Everyone starts somewhere! This is where CSS comes in. CSS stands for Cascading Style Sheets, and it's how we add style to our HTML. The quickest way to start styling is with inline CSS using the style attribute.
GrumpyMcTweak
Fine. If we MUST change things, at least inline CSS keeps the styling contained and easy to track. Let's add some BASIC styles to that heading. Nothing fancy! Security first!
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 style="color: blue; font-size: 32px;">Welcome to My Page</h1>
<p>This is a paragraph about me. I like coding and learning new things.</p>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</body>
</html>
Welcome to My Page
This is a paragraph about me. I like coding and learning new things.
- HTML
- CSS
- JavaScript
FattyMcTweak
That's like putting a single sprinkle on a sundae and calling it dessert! If we're doing inline styles, let's GO FOR IT! Premium styling with ALL the trimmings! Let me show you how to really make this page POP!
<!DOCTYPE html>
<html>
<head>
<title>My AWESOME Webpage</title>
</head>
<body style="background-color: #f0f8ff; font-family: Arial, sans-serif; margin: 20px; padding: 20px;">
<h1 style="color: #4b0082; font-size: 42px; text-align: center; text-shadow: 2px 2px 4px #cccccc; border-bottom: 2px solid #4b0082; padding-bottom: 10px;">Welcome to My AMAZING Page</h1>
<p style="color: #333333; font-size: 18px; line-height: 1.6; margin-top: 20px; padding: 15px; background-color: #e6e6fa; border-radius: 8px;">This is a paragraph about me. I like coding and learning new things.</p>
<ul style="list-style-type: square; background-color: #e0ffff; padding: 20px; border-left: 5px solid #4b0082; margin-top: 20px;">
<li style="color: #8a2be2; margin-bottom: 10px; font-weight: bold;">HTML</li>
<li style="color: #ff1493; margin-bottom: 10px; font-weight: bold;">CSS</li>
<li style="color: #ff8c00; margin-bottom: 10px; font-weight: bold;">JavaScript</li>
</ul>
</body>
</html>
Welcome to My AMAZING Page
This is a paragraph about me. I like coding and learning new things.
- HTML
- CSS
- JavaScript
GarbageMcTweak
For the love of... this is why inline CSS should be used sparingly. If you need to update that styling later, you'll be hunting through every HTML tag like you're looking for a specific piece of hay in a haystack. Inline styles have their place, but this is not it.
AllyMcTweak
Garbage is right. Inline CSS is good for quick testing or one-off styling, but it becomes hard to maintain for larger sites. Let's find a balance - use inline CSS where it makes sense, like for highlighting specific elements, but we'll learn better ways in the next episodes.
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 style="color: #4b0082; font-size: 32px; text-align: center;">Welcome to My Page</h1>
<p style="color: #333333; font-size: 16px;">This is a paragraph about me. I like coding and learning new things.</p>
<ul style="background-color: #f0f8ff; padding: 15px;">
<li style="color: blue;">HTML</li>
<li style="color: red;">CSS</li>
<li style="color: green;">JavaScript</li>
</ul>
</body>
</html>
Welcome to My Page
This is a paragraph about me. I like coding and learning new things.
- HTML
- CSS
- JavaScript
CodyMcTweak
So there you have it! Inline CSS uses the style attribute to add styling directly to HTML elements. It's great for quick changes, but can get messy for larger projects. In the next episode, we'll learn about internal style sheets, which solve many of these problems!