Welcome to the Power Users community on Codidact!
Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.
How do I color — some but NOT all — text in a sentence, in HTML5?
My corporation has a discussion forum that uses HTML. I'm uncertain if this is HTML5, and if it also uses CSS.
<font color="red">Color this red.</font>
failed, probably because "The color attribute is not supported by HTML5".
<p style="color:red;">Red paragraph text</p>
worked. But this code DOESN'T answer my question — because I want just some but NOT ALL text, in a sentence, coloured. I don't want the whole para. colored!
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
TextKit | (no comment) | Dec 8, 2021 at 00:24 |
The font
element is depreciated
An easy way to do it is to use span
elements. That page has a good example of what you want. Simply do something like
<p>Blah blah <span class="special">special text</span> blah blah</p>
You can easily style the special text with CSS. If the styling is not purely decorative though, I would recommend using sematic HTML and using, for instance strong
or b
, both of which are used to draw emphasis to certain parts of a text. Though they default to boldface, you can change the styling however you want.
3 comment threads