10 Simple CSS Code Examples You Can Learn in 10 Minutes

Once you’ve started dabbling in HTML, you’ll probably be interested in adding more power to your web pages. CSS is the best way to do that. CSS lets you apply changes across your entire page without having to use lots of inline HTML styles. computer science computer science computer science computer science computer science computer science

We’ll go over how to create an inline stylesheet so you can practice your CSS skills, and then we’ll move onto 10 simple examples that will show you how to do a few basic things. From there, your imagination is the limit!

Inline Stylesheet

Every HTML document contains a <head> tag. That head section is where your inline CSS stylesheet goes. Here’s what it’ll look like: computer science computer science computer science computer science computer science computer science

<head>
  All of your CSS declarations.
</head>

Put that at the top of your document, fill it with your CSS, and you’re set to go.

1. Easy Paragraph Formatting

The cool thing about styling with CSS is that you don’t have to specify a style every time you create an element. You can just say “all paragraphs should have this particular styling” and you’re good to go. Here’s an example of how you might do that. computer science computer science computer science computer science computer science computer science

Let’s say you want every paragraph (that’s everything with a <p> HTML tag) on your page to be slightly larger than usual. And dark grey, instead of black. Here’s how you would do that with CSS:

p {
  font-size: 120%;
  color: dimgray;
}

That’s all there is to it. Now, whenever the browser renders a <p> paragraph, the text will inherit the size (120 percent of normal) and the color (“dimgray”).

If you’re curious as to which plain-text colors you can use, check out this CSS color listfrom Mozilla.

2. Change Letter Case

Okay, so now that we’ve seen how to make a change to every paragraph, let’s look at how we can be a bit more selective. Let’s create a designation for paragraphs that should be in small caps. Here’s how we’d do that: computer science computer science computer science computer science computer science computer science

p.smallcaps {
  font-variant: small-caps;
}

To make a paragraph that’s entirely in small caps, we’ll use a slightly different HTML tag. Here’s what it looks like:

<p class="smallcaps">Your paragraph here.</p>

As you can see, adding a dot and a class name to any specific element in CSS specifies a sub-type of that element defined by a class. You can do this with text, images, links, and just about anything else.

If you want to change the case of a set of text to a specific case, you can use these CSS lines:

text-transform: uppercase;
text-transform: lowercase;
text-transform: capitalize;

The last one capitalizes the first letter of every sentence.

Prev1 of 6Next

Leave a Reply

Your email address will not be published. Required fields are marked *