Home » Technology » Front-End Development: Styling With CSS

Front-End Development: Styling With CSS

by Geeky Nigeria
3 minutes read

Basic styling in CSS can enhance the visual appeal of your HTML document. You can incorporate CSS directly in your HTML file using the <style> tag, located inside the <head> section.

CSS works through selectors, properties, and values, allowing you to customize elements. For example, with a selector targeting h1, you could set properties

Additionally, you can link to an external CSS file using the <link> tag, providing a clean separation of style from content.

N.B: CSS Elements are always in American English. For instance, it’s always “color”.

Adding CSS to Style Your HTML Document

Including CSS in your HTML document can significantly enhance its visual appeal and user experience.

There are three primary methods for integrating CSS: internal stylesheets, inline styles, and external stylesheets. Each approach has its specific use cases and benefits.

Internal stylesheets will be the scope of this article. It is included within the <head> section of your HTML.

You define your styles in a <style> tag, which allows all elements within that document to access the defined styles:

Internal Styles are included under the Head tag

We can then style different elements of the page under the style tag. For instance, we can change the color of the paragraph (<p>) to green by inserting the following code:

p {     color: green;   }

Change the colour of the paragraph text to green under the style tag

Save your HTML document, then open it in your browser, you should have something like this:

 

Browser result after changing Paragraph text to green in styles.

Next, we are going to style the Heading, with a basic styling example to set the font size and color of the h1 element. Using CSS, you can easily define these attributes:

h1 {    font-size: 2.5em;
         color: red;}

In the above code, the font-size property increases the size of the heading to 2.5 times the standard size, while the color property changes the text color to red.

The code should look like this in sublime text:

Add styling for heading H1

When viewed in your web browser, you should have something like this:

Browser output of changing Heading to Red

Positioning is a significant aspect of styling. The text-align property can be utilized to align the text sections:

h1 {    text-align: center;}

This aligns the header text to the center of its containing element, adding an element of symmetry to your webpage.

The code should appear like this in Sublime Text:

Style H1 to Center

Save the file and view it in the browser, you should get the following:

Lastly, we will are going to style the body.

One of the first properties to consider when styling the body element is the background-color. For instance, using CSS, you can easily set a light background color to enhance readability. We are also going to add a margin which enhances readability and ensures that text does not run to the edges of the browser window.

body {    background-color: #f0f0f0;
            margin: 20px}

Add background color and margin to Body element

When viewed on your browser, you should get the following output:

Browser output from styling background and adding margin.

In our next article, we will talk about bringing HTML elements to life with Javascript.

Did you miss the HTML Introduction? – Front-End Development: Getting Started With HTML

Next, learn how to animate with Javascript – Front-End Development: Animate With Javascript!

You may also like

At Geeky Nigeria, we’re passionate about providing high-quality content that’s engaging, informative, and relevant to our audience.

Random Pick

Latest Articles

© 2025 Geeky Nigeria, All Rights Reserved.

error: Content is protected !!