On this page you will find simple CSS examples (with HTML) that you can copy and paste into the PlayCode123 Code Sandbox.
If you are a complete beginner, it is helpful to first try some HTML examples and then come back here to style your pages with CSS.
Reminder: CSS (Cascading Style Sheets) changes how your page looks.
In these examples, CSS is placed inside a <style> tag in the
<head> of the HTML document. In real projects, you usually keep
most CSS in one <style> block or in a separate file
(for example styles.css).
This example sets the background color of the whole page using the
body selector.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Background Color Example</title>
<style>
body {
background-color: lightblue;
}
</style>
</head>
<body>
<h1>Aquatic Plants</h1>
<p>The background of this page is light blue.</p>
</body>
</html>
lightblue to another color,
for example lightgreen or pink.
This example changes the text color of the page using the
color property on the body element.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Text Color Example</title>
<style>
body {
color: green;
}
</style>
</head>
<body>
<h1>Aquatic Plants</h1>
<p>All the text on this page is green.</p>
</body>
</html>
green to another color,
such as darkblue or brown.
This example changes the color of all <h1> elements and
centers them.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Heading Style Example</title>
<style>
h1 {
color: yellow;
text-align: center;
}
</style>
</head>
<body>
<h1>Aquatic Plants</h1>
<p>This heading is yellow and centered.</p>
</body>
</html>
text-align: left; or text-align: right;.
This example shows how to align paragraphs to the center or to the right.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Paragraph Alignment Example</title>
<style>
p.centered {
text-align: center;
}
p.right {
text-align: right;
}
</style>
</head>
<body>
<p class="centered">This text is centered.</p>
<p class="right">This text is aligned to the right.</p>
</body>
</html>
This example shows how to choose a font for all <p>
elements on the page.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Font Family Example</title>
<style>
p {
font-family: Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Winding Water Plants</h1>
<p>This paragraph uses the Verdana font (or a similar font).</p>
</body>
</html>
Georgia or "Times New Roman".
This example changes the font size of paragraphs using
font-size.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Font Size Example</title>
<style>
p {
font-size: 1.2em;
}
</style>
</head>
<body>
<h1>Different Aquatic Plants</h1>
<p>This paragraph text is a bit larger.</p>
</body>
</html>
font-size: 2em; or
font-size: 18px; and see the difference.
This example uses an ID selector to style a single paragraph.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ID Selector Example</title>
<style>
#beautifulaquaticplants {
color: brown;
font-weight: bold;
}
</style>
</head>
<body>
<p id="beautifulaquaticplants">Various beautiful aquatic plants.</p>
<p>This paragraph has the default style.</p>
</body>
</html>
text-decoration: underline; to the ID selector.
This example uses a class selector to style several paragraphs in the same way.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Class Selector Example</title>
<style>
p.aquaticplants {
color: brown;
}
</style>
</head>
<body>
<p class="aquaticplants">Aquatic plants in cold regions...</p>
<p class="aquaticplants">Aquatic plants in tropical regions...</p>
<p class="aquaticplants">Aquatic plants in subtropical regions...</p>
<p>This paragraph has default styling.</p>
</body>
</html>
font-style: italic; to the class,
and see all three paragraphs change.
This example shows how to use inline styles directly on HTML elements.
This is fine for small tests, but for bigger websites it is better to
keep most CSS in a <style> block or a separate file.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Inline Style Example</title>
</head>
<body>
<h1>Food Sources</h1>
<mark style="background-color: blue; color: white;">
Aquatic plants are food sources
</mark>
<p style="background-color: green; color: white;">
Aquatic plants are food sources<br>
for many animals,<br>
and they also serve as shelters.
</p>
</body>
</html>
This example creates a simple “card” with a border, padding and a different background color.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Card Style Example</title>
<style>
.card {
border: 1px solid #333;
background-color: #f0fff0;
padding: 20px;
margin: 20px;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="card">
<h1>Aquatic Plant Card</h1>
<p>This box has a border, padding and a light background color.</p>
</div>
</body>
</html>
border-radius to make the corners more round.