Topics in this sectionIntroduction to Web Design2 topics
- HTML Basics
- CSS Styling
CSS Styling — Adding Color and Design to Web Pages
When you create a webpage using HTML, the browser shows plain content by default. All headings look the same, all paragraphs look the same, and there is no color. CSS (Cascading Style Sheets) lets you change how HTML elements appear. You can add colors, change font sizes, set margins, and make your page attractive. This is what we mean by "styling" — giving your webpage a visual design.
CSS is a language that works together with HTML. HTML provides the structure (the content, headings, paragraphs, images, and tables), while CSS provides the presentation (colors, fonts, spacing, borders, and layout). When you apply CSS to your HTML, you tell the browser exactly how each element should look.
Think of it like building a house. HTML is the frame and walls — the structure. CSS is the paint, tiles, and decorations — the visual finish. Both are needed to create a complete webpage.
A CSS rule has two main parts: the selector and the declaration block.
The selector tells which HTML element to style. For example, if you want to change all paragraph text, your selector is the letter p. If you want to change the main heading, your selector is h1.
The declaration block goes inside curly braces { }. Inside the braces, you write declarations. Each declaration has two parts: a property and a value, separated by a colon and ending with a semicolon.
Here is a complete CSS rule:
h1 {
color: blue;
font-size: 32px;
}
In this example:
h1is the selector (it selects all level-1 headings)color: blue;is a declaration —coloris the property,blueis the valuefont-size: 32px;is another declaration —font-sizeis the property,32pxis the value
You can add as many declarations as you need inside one rule. Each element you style gets its own rule.
There are three ways to add CSS to a webpage:
- Inline CSS — writing the style directly inside an HTML tag using the
styleattribute - Internal CSS — placing all CSS rules inside a
<style>tag in the<head>section of the HTML page - External CSS — keeping all CSS rules in a separate file (usually named
style.css) and linking it to the HTML page
For learning purposes, internal CSS is the easiest to start with. You write your rules inside the same file as your HTML.
Here is a simple HTML page with internal CSS:
<!DOCTYPE html>
<html>
<head>
<title>Rumbek School Website</title>
<style>
body {
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
h1 {
color: #006600;
text-align: center;
}
p {
color: #333333;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Welcome to Rumbek Secondary School</h1>
<p>Our school offers quality education for all students.</p>
</body>
</html>
In this example, the <style> block contains three CSS rules. The body rule sets the background color and font for the whole page. The h1 rule makes the heading green and centers it. The p rule styles all paragraphs with dark gray text and a font size of 16 pixels.
CSS allows you to specify colors in several ways. Understanding these different formats is important because you will see all of them when reading or writing CSS.
Color Names
The simplest way to specify a color is by using its English name. CSS supports many standard color names such as red, blue, green, yellow, black, white, orange, purple, gray, and cyan. For example:
h2 {
color: red;
}
This method is easy but limited. There are only about 140 standard color names, and they may not give you the exact shade you want.
RGB Values
RGB stands for Red, Green, and Blue. Every color on a computer screen is made by combining different amounts of these three colors. In CSS, you specify an RGB value using the formula rgb(red, green, blue), where each number ranges from 0 (none of that color) to 255 (maximum of that color).
For example:
rgb(255, 0, 0)is pure red (maximum red, no green, no blue)rgb(0, 255, 0)is pure greenrgb(0, 0, 255)is pure bluergb(255, 255, 0)is yellow (red + green)rgb(0, 0, 0)is black (no color)rgb(255, 255, 255)is white (all colors combined)
Here is how you use an RGB value in CSS:
p {
color: rgb(0, 128, 0);
}
This sets the paragraph text to a dark green color.
Hexadecimal Codes (HEX)
Web designers most commonly use hexadecimal (HEX) codes to specify colors. A HEX code starts with a hash symbol # followed by six characters. The first two characters represent the amount of red, the next two represent green, and the last two represent blue.
Each pair of characters can range from 00 (0 in decimal) to ff (255 in decimal). For example:
#ff0000is pure red#00ff00is pure green#0000ffis pure blue#000000is black#ffffffis white
Shorter HEX codes using three characters are also valid for simple colors:
#f00is red#0f0is green#00fis blue
Here is a practical example using HEX:
h1 {
color: #006400;
}
This sets the heading color to a deep green often used for forest colors.
When choosing colors, you can use online color pickers to find the HEX or RGB values you need. Many free tools let you select a color visually and then copy the resulting code.
Imagine you are creating a webpage for a small shop in Juba market. You want the page to have a cream-colored background, dark brown headings, and dark text. Here is how you would write the CSS:
<!DOCTYPE html>
<html>
<head>
<title>Nile General Store</title>
<style>
body {
background-color: #fffdd0;
font-family: Verdana, sans-serif;
}
h1 {
color: #8b4513;
text-align: center;
}
h2 {
color: #a0522d;
}
p {
color: #333333;
line-height: 1.6;
}
.highlight {
background-color: #ffd700;
padding: 5px;
}
</style>
</head>
<body>
<h1>Nile General Store</h1>
<p>Welcome to your one-stop shop for household items in Juba.</p>
<h2>Our Products</h2>
<p>We sell sorghum, dura, cooking oil, soap, and many other daily needs.</p>
<p class="highlight">Special offer: 20% off all cooking oil this week!</p>
</body>
</html>
Notice the last paragraph has class="highlight" inside the HTML tag. In CSS, you can create a rule for a class by writing a dot (.) before the class name. This lets you apply a specific style to certain elements only, not all of them.
Here are several properties you will use frequently when styling webpages:
color— changes the text colorbackground-color— changes the background color behind an elementfont-size— sets the size of the text (usepxfor pixels, e.g.,16px)font-family— specifies which font to use (e.g., Arial, Times New Roman)text-align— aligns text to the left, right, center, or justifiedmargin— adds space outside an element's borderpadding— adds space inside an element, between the content and its borderborder— adds a border around an element (specify width, style, and color)
Each of these properties takes values in specific formats. For example, margin: 20px; adds 20 pixels of space around all sides of an element. You can also specify different sides: margin-top, margin-bottom, margin-left, and margin-right.
When you apply the same styles to all similar elements on your page, your webpage looks professional and is easier to read. For example, all your level-2 headings should look the same throughout the page. All paragraphs should have the same font size and line spacing.
Inconsistent styling confuses visitors. If one paragraph is large and another is small, readers will wonder if the content is different in importance. By using CSS, you set a rule once and apply it everywhere, ensuring consistency.
This is also why external CSS files are useful for larger websites. When all pages link to the same CSS file, you can change the design of the entire website by editing just one file.
A small business owner in Juba or Wau can use CSS to create a simple online catalogue for their shop. By applying consistent colors, fonts, and spacing, they can make their webpage look professional and trustworthy. For example, a dukа (small shop) selling groundnuts at a boma market could create a webpage with green and yellow colors — colors associated with agricultural produce — and use CSS to make product descriptions clear and easy to read. This helps attract customers and grow the business.
Question
What is the selector in the following CSS rule?
Sign in to submit your answer and have it count toward your mastery.
Sign in to practiceTutor
Stuck? Ask me anything about this topic.
Sign in to ask the Sonza AI Tutor about this question.
Sign in to askDiscussions
No questions yet