Publishers of technology books, eBooks, and videos for creative people

Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Basic Properties: Font Styles

CSS support in browsers began with simple text style properties, so it's fitting that we begin our investigation into CSS properties with these foundational properties.


The color property specifies the text color for selected elements.

The property takes a single color value. Color values, which are also used by a number of other CSS properties, come in a number of forms.

The simplest color values are color keywords, of which there are two kinds: seventeen basic color values like red and blue, and a larger number of system colors, including ButtonFace, ButtonText, and other values. In addition, all browsers have long supported a large palette of 140 color keywords from the X11 color chart, and though these are not part of CSS1 or CSS2, they are part of the draft versions of CSS3.

The seventeen common colors are aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow. A full list of the X11 colors can be found at

System colors don't set text to a specific color—instead, they let developers match the style of their own elements (like buttons) to the current system colors as defined in each user's operation system preferences, thus harmonizing their interfaces with the system's.

Color in CSS can also be specified in a number of other ways, the most common of which is hexadecimal RGB colors. These have the form #RRGGBB, where RR is a red hexadecimal color value, GG is a green hexadecimal color value, and BB is a blue hexadecimal color value. You won't generally need to manually determine the color value, as most design tools do this part for you, but now you know what the code means. When all three colors have their two digits or letters repeated (for example, #FF2277), the value can be truncated using the form #RGB (in this case, #F27). Note that this truncation can occur not when the second digit is a zero, but when the digit or letter for each color value is repeated. One very common CSS error is leaving off the # at the beginning of the hex value; don't do this. The third and fourth way to specify color values is via decimal and percentage RGB colors. Both of these methods have the basic form rgb(color value), with the color value inside the parentheses. In decimal RGB, a number between 0 and 255 is used for each color, with these values separated by a comma. In percentage RGB, a percentage value from 0% to 100% is used. So, orange, which is #FFA500 in hexadecimal, would be rgb(255, 165, 0) in decimal RGB and rgb(100%, 65%, 0%) in percentage RGB.

Let's cut to the chase and give our body a color of orange:

body {
  color: orange;

We've created our first statement. Easy, right?


Next, we'll give our headings a font. In CSS, we use the font-family property for this. This property takes one or more font names, separated by a comma. Why specify more than one? In CSS, we can generally only use the fonts already installed on our users' systems. There are exceptions to this rule, but web typography is sufficiently complex to deserve its own chapter (Chapter 15), so we'll stick with basics for now. The fonts on users' computers will depend on their operating systems, what fonts they have installed themselves, what software (such as Microsoft Office) they have installed, and several other factors. If we could only specify a single font, we'd really be stuck with the tiny subset of fonts that all platforms have in common. Luckily, we can specify more than one, so we can take advantage of a wider range of fonts. It's usually best to use a set of fonts that are similar to each other—by which I mean not simply fonts that look alike, but that have similar metrics—so that the same characters will occupy a similar amount of space in the various fonts we select.

A common pair of fonts with very similar metrics is Helvetica and Arial. One or the other of these two fonts are found on most browsing platforms, so specifying both together makes a lot of sense. We'd do this with the font-family property like this:

font-family: Helvetica, Arial

It's also a good idea to use a fallback generic font family, of which CSS provides five:

  • serif
  • sans-serif
  • monospace
  • cursive
  • fantasy

Here's how this all works together. When a browser sees the font-family property, it takes the list of font names (which are separated by commas) and looks to see whether the user's system has a font that matches the first name. If so, it uses this font. If not, it goes to the next font name, and sees whether it has a match for this one. If so, it uses that; otherwise, it continues along the list. You can name as many alternate fonts as you like. If none of the names match a font on the user's system, the browser takes the generic family name and uses either its default font for that family or the user's preferred font for that family (most browsers let you set a preferred font for generic families).

When a font has one or more spaces in its name—like Times New Roman—the name of the font must be wrapped in single or double quotation marks. For example:

font-family: Times, "Times New Roman", serif

Common mistakes with the font property include using quotation marks with font names that don't have spaces, using quotation marks with generic font family names (particularly sans-serif), and not using quotation marks with font names that do have spaces.


You can set the size of text with the font-size property. font-size is the first property we've seen that takes more kinds of values: length values and percentage values.

Length Values

A length value is a numeric value associated with a unit of measurement. In CSS, with very rare exceptions, when a property takes a numeric value, that value includes a unit. In HTML, unitless numeric values are assumed to be px values, but in CSS, a length value without a unit is almost always considered an error; there are one or two exceptions, which we'll discuss shortly. This is one of the most common errors CSS developers make, and it's so common in part because some browsers wrongly treat numeric values with no units as pixel values. There are several different units, the most common being pixels (px) and ems (em). Percentage values, though they're not strictly length values, are very similar to length values; the trick is that percentage values don't always refer to the same thing from property to property, as we'll see shortly.

Relative and Absolute Values

There are two types of length value—absolute values, which are most commonly length values with a px unit, and relative values, which are most commonly values with an em unit. Percentage values are effectively relative values as well.

Absolute length values are (usually) fixed, regardless of factors like the user's text zoom, window size, and so on. Relative values allow layouts, text size, and other CSS-applied styles to adapt to the user's preferences and setup, so they're generally preferred. We'll see plenty of examples of the benefits of relative units throughout this book, but some very common examples include:

  • Specifying font-size in em units or percentages. This allows for text to grow and shrink as users increase and decrease their font size (this is less of a problem today, but older browsers typically fixed the size of text so that it couldn't be zoomed by the user if the unit for font-size was pixels).
  • Specifying the width of an element in ems. This means that the element remains more or less the same number of characters wide regardless of how big or small the text is zoomed. This can be especially helpful for legibility, where particularly long or short lines of text can very much impact the ease of reading.

It's possible to set font-size in pixels, but it's much more preferable to set it in either percentages or ems. We could set our headings to have different font sizes using statements like these:

h1 {font-size: 2em}
h2 {font-size: 1.6em}
h3 {font-size: 1.4em}
h4 {font-size: 1.2em}

This means that the text of h1 elements will be twice the size that it would otherwise be, h2 elements 1.6 times the size it would otherwise be, and so on. We could similarly use equivalent percentages to do this:

h1 {font-size: 200%}
h2 {font-size: 160%}
h3 {font-size: 140%}
h4 {font-size: 120%}

Much less common is the use of keywords to specify font sizes. It is possible to use keywords like xx-small, small, and large, but it's usually best to avoid these, as there's no consensus among browsers—or in the CSS standard—as to exactly what these seven sizes should be in relation to one another.


The font-weight property, which controls how bold or heavy a font should be, can be specified in two ways: we can use the keywords bold and normal, or we can use one of nine weights from 100 to 900. It's rare that fonts have a wide range of weights, and so values of 100 to 400 map typically to the value of normal, and 500 and up are considered bold.


One of the challenges of becoming proficient in CSS is learning and remembering all the different possible property names, which don't always align with what we commonly call these properties outside of CSS. A perfect example is how we specify whether an element's text should be italicized. In CSS, we use the font-style property, with three possible keyword values—italic (not italics), normal, and oblique. We can essentially consider italic and oblique to be the same thing.


With the text-decoration property, we can add or change text strikethrough, underline, the far less commonly used overline, and the mercifully unused and largely unsupported blink decorations. The text-decoration takes one or more space-separated (not comma-separated) keyword values:

  • underline
  • overline
  • line-through
  • blink
  • none (which removes, for example, the default underline most browsers apply to anchors)

Putting these common properties together, we might style a heading of level 1 like this:

  font-family: "Times New Roman", Times, serif;
  font-weight: bold;
  font-style: italic;
  text-decoration: underline;
  font-size: 2em;
  • + Share This
  • 🔖 Save To Your Account

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive:

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020