Multicoloured text in HTML

1o0oBhP 0 Tallied Votes 372 Views Share

Without using cascading style sheets or more complicated methods it is easy to introduce coloured text into your HTML sites/documents. This is done by using the <font> tag and its options. In addition to this the <font> tag is more backwards-compatible than most other style commands.

The way to do it is: <font color=#RRGGBB>your text here</font> where RR GG and BB are the colour componenets in hexadecimal. Try veiwing the following example

[CODE]
<html>
    <head>
        <title>Multi-Coloured Text example &copy1o0oBhP :)</title>
    </head>
    <body>
        <table>
            <tr><td><font color="#FF0000"><b>This is RED text</b></font></td><td><b><font color="#FF0000">RRGGBB = FF0000</font></b></td></tr>
            <tr><td><font color="#00FF00"><b>This is GREEN text</b></font></td><td><b><font color="#00FF00">RRGGBB = 00FF00</font></b></td></tr>
            <tr><td><font color="#0000FF"><b>This is BLUE text</b></font></td><td><b><font color="#0000FF">RRGGBB = 0000FF</font></b></td></tr>
        </table>
    </body>
</html>
[/CODE]

Dani AI

Generated

Quick, practical context: the example from shows the old inline approach to colouring text. That method will still render in many legacy browsers, but the font element is obsolete in HTML5 and mixes presentation with content. Modern practice is to use CSS for colors and effects — it improves maintainability, theming, and accessibility. 's note about snippet formatting is relevant when sharing examples, and 's point about named colours is correct but limited in precision compared with modern CSS color models.

A minimal, modern pattern uses CSS custom properties and classes for predictable results and easy theme swapping. Example:

:root {
  --accent: hsl(210, 90%, 56%);
  --accent-alt: hsl(330, 70%, 50%);
  --fallback: #222222;
}

.colored { color: var(--accent); }

.grad {
  color: var(--fallback);                     /* sensible fallback */
  background: linear-gradient(90deg,var(--accent),var(--accent-alt));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;       /* WebKit */
  background-clip: text;                      /* modern browsers */
}

Use these classes on inline elements such as span or on headings. Keep class usage consistent instead of sprinkling inline styles.

Important practical notes: preserve sufficient contrast (WCAG targets: 4.5:1 for normal text, 3:1 for large text), and never rely on color alone to convey meaning. For decorative headings, gradient text and clipping are fine but include a solid-color fallback for older browsers and email clients. When dealing with legacy content that still uses font tags, plan a progressive migration to CSS classes (batch replace or template updates) so styling can be centrally managed and accessibility checks applied consistently.

1o0oBhP 4 Posting Pro in Training

Hmmm, the formatting didnt come out right, even with code tags...

Dani 5,664 The Queen of DaniWeb Administrator Featured Poster

I am still working on perfecting the engine which powers these code snippets. Not all languages are full supported, but I can assure you that I am working on it!

1o0oBhP 4 Posting Pro in Training

no worries, i thought that code tags preserved the formatting? its worked before when i have copied/pasted from devc++, i might write the html in devc++ and paste and see what happens...

1o0oBhP 4 Posting Pro in Training

Hmm it is ignoring the code tags by the look of things... dunno if that is something to check?

Dani 5,664 The Queen of DaniWeb Administrator Featured Poster

There is no need for code tags in the Code Snippets library. The language the code is written in determines how it's formatted.

anastacia 0 Junior Poster

ACTUALLy the code for colours is in hexadecimal form but you can even put the color name
<html>
<body>
<font color="red"> this will be in red </font>
</body>
</html>
however it depends upon your browser not all browser support all colours

mmiikkee12 1 Posting Whiz in Training

<font color="crap"> makes a dingy brown...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.