inset text effect with css

How to create inset text with CSS Web design (for beginners)

Inset text can make your Web design look beautiful, and while it is cutting edge, it's also super easy for beginners to implement using CSS and a bit of HTML.

Creating text with subtle shadows and shading, that gives the impression of depth, is a widely used Web design technique on many leading blogs and websites.

You can even see it in action in the SME Pals site name - and best of all, it uses lightweight, clean CSS instead of clunky, slow images.

This article will tell you what you need in order to create a beautiful Web design using inset text with CSS and HTML, and shows how to implement it, step-by-step.

HTML & CSS

Unlike my previous articles on Web design using CSS3, like Killer CSS3 Web design tips for complete beginners, that only required a class or id attribute in order to attach various styles, we actually need to be able to edit the HTML elements that wrap the text we want to inset.

So, you need access to the website's underlying HTML, as well as the CSS stylesheets. Alternatively, make sure you are using one of the leading website builders like Weebly or Bigcommerce (for shopping carts) that allow for customization of HTML and CSS code.

If you don't have access to stylesheets, then it is possible to add the CSS declarations to your webpages using the <style> tag.

Designing inset text step-by-step

In order to properly implement the inset text design, we will need to use a few nifty CSS tricks, including opacity, positioning, and the :before qualifier.

Let's begin by creating some text standard text...

1. Create the HTML

Inset text is only really effective on larger fonts, and in particular, bold text - on small type it can make things harder to read.

So, we should only really consider adding inset design to page titles or headings. Let's create an inset heading and give it a class that we can use to style it, like this:

<h2 class="inset" title="Inset text">Inset text</h2>

Note the inclusion of the title attribute. It's important because we are going to use it in the CSS next.

2. Style the HTML with CSS

By itself, this heading will pick up the default H2 heading style of the site, so we are going to change things up a bit by giving it its own CSS class declaration, like so:

h2.inset{
font-size: 5em;
font-weight: 900;
color: #224970;
font-family: Georgia;
}

This makes our header look like this:

Inset text

3. Apply inset shadow using :before

Now comes the cool design part.

We can attach an additional style to this class using the title attribute (which is why we included title in the HTML), and style it with some neat effects to give the impression of light falling across inset copy:

h2.inset:before{
font-size: 5em;
font-weight: 900;

position: absolute;
margin: 2px 0 0 2px;
content:attr(title);
color: #fff;
opacity: 0.2
filter:alpha(opacity=20);

}

The important parts are highlighted in the CSS above. Effectively, our CSS style instructions are:

  1. Insert content "before" the h2.inset element
  2. Position it absolutely so that it appears "on top of" the target element
  3. Offset it slightly with margins
  4. Make the content the same as specified in the element's title attribute
  5. Give it a white coloring
  6. Make it opaque

If you get the margins just right, the effect is pretty striking:

Inset text

4. Shading & colors

Now while you can probably see the inset from the code above, it is not as effective as it could be because the white highlighting on the edges of the text is obscured by the light background of the page.

It's important to get the coloring just right to imitate that beautiful "soft" appearance that the leading Web designers achieve.

We can put the exact same text on a darker background to give it more visual impact:

Inset text

Obviously, you will need to play around with the colors so that they match the color scheme of your theme or template. Many high quality themes come with this effect built in, so it is worth exploring some of the leading theme developers (for WordPress, and other leading CMS systems) too.

So that's how I create an inset text Web design effect. Was this easy for you to get right, or is there a better/easier way to do it?

Share your thoughts in the comments, or send me a link of the design you created with this technique.

Found This Useful?

Share it on your own site using this quick link (and tell us about it in the comments so we can read your article too).

Old HTML tables can be upgraded into a responsive design with CSS3 and media queries

Mobile first, responsive Web design is something that can't be ignored because devices likes tablets and smartphones are quickly becoming the dominant browsing device of choice for the burgeoning millennial market.

If you are one of those unlucky people to have built your site more than a few years ago, on a platform that used the old table based Web design paradigm, then you have two choices: