Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Use CSS to change font style of part of a paragraph?

Featured Replies

Sorry if this is a really silly question!

If I wanted to italicise part of a paragraph, using css instead of the old <font tag, can I do it? Surely I just can't wrap a div class around one word inside a paragraph?

  • Author

OK, a bit more googling found that apparently <em>, <u>, <strong>, <b>, <i> tags are still valid XHTML.

But I was thinking of styling it a bit more than that. Can I set anywhere that bold would also change colour to white or anything? (Most text is off-white grey so I though bold and bright white would stand out nicely)

<p>This is normal text <em>this is italic by default in most browsers</em> <span class="italic">this is italic colored</span> text</p>

 

CSS

.italic { font-style: italic; color: #ffff00; }

 

Read this http://html5doctor.com/i-b-em-strong-element/

Edited by Wickham

<em> is the proper and semantic way of doing things as it stands for "Emphasise".

 

You can then apply any CSS to this, say it's in a paragraph with a class of 'pclass1' it would be styled like so...

 

.pclass1 em {
color:#fffff;
}

Edited by MikeChipshop
Beaten by super quick fast Wickham!

  • Author

That's fantastic, Many Thanks! So I guess a simple italic could use <i> and any text that I wanted to 'emphasise' in whatever way was my chosen style would use <em>

  • Author

Do I need .pclass1 or can I specify this by itself as em if I want it to be used anywhere?

  • Author

Forget that! I've just tried and found I can.

 

Just what I was looking to do and very informatively answered, many thanks guys!

Use <em>...</em> by itself if you just want italic or combine it with a class if you want color or underline or want to change italic back to normal

.pclass1 {
color:#fffff;
}

<p><em class="pclass1">..............</em></p>

 

You've got lots of alternatives. Note that Mike's .pclass1 em {} requires the class in an element preceding the em tag while my .pclass1 {} has to be inside the <em> tag.

Edited by Wickham

By default in all browsers <em> will italicise text without any other styling being applied by yourself.

My 'pclass1' class was just an example of how to style the <em> tag if you needed to.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.