The index relative to the text is the displacement of characters relative to the baseline up or down. Depending on the positive or negative value of the offset, the index is called upper or lower, respectively. They are actively used in mathematics, physics, chemistry and to designate units of measurement. HTML offers two elements for creating an index: (from English superscript) - superscript and (from English subscript) - subscript. Text placed in one of these containers is designated smaller than the base text and is offset up or down relative to it. Example 1 shows sharing specified elements and styles to change the appearance of the text.

Example 1: Creating a superscript and a subscript

Superscript and subscript .formula ( font-size: 1.4em; /* Formula text size */ ) sup, sub ( font-style: italic; /* Italic */ color: red; /* Red color of characters */ ) sub ( color: blue; /* Blue color of characters */ )

Characteristic equation of a surface of the second degree

λ3 - I1λ2 + I2λ - I3 = 0

In the example, both subscript and superscript appear simultaneously. To change the index font style, styles are used that set a uniform design (Fig. 1).

Rice. 1. View of indexes after applying styles

You can refuse to use them altogether in favor of styles. An analogue of these elements is the vertical-align property, which causes the text to be shifted vertically by a specified distance. Specifically, in Example 2 the value is 0.8em for the superscript and -0.5em for the subscript. Em is a relative unit equal to the size of the current font. For example, 0.5em indicates that the text should be shifted by half the font size.

Example 2: Using Styles to Manage Indexes

Superscript and subscript .formula ( font-size: 1.6em; /* Text size */ font-style: italic; /* Italic style */ ) .sup, .sub ( font-style: normal; /* Normal style * / font-size: 0.6em; /* Index size */ color: red; /* Superscript color */ vertical-align: 0.8em; /* Shift text up */ .sub ( color: blue; /* Color subscript */ vertical-align: -0.5em; /* Move the text down */ )

Polynomial of degree n

f(x) = a0 + a1 x + ... + an-1 xn-1 + an xn

In the example, the formula itself is displayed in an enlarged size, the superscript symbols are set in red, and the lower ones in blue (Fig. 2).



Convert lowercase letter to lowercase and first uppercase with using CSS (8)

There is no cap clause option in CSS. Other answers suggesting text-transform: capitalize are incorrect because this option uses every word for every word .

Here rude way to do this is if you want the first letter of each element to be in uppercase, but this is definitely nowhere near the actual limits:

P ( text-transform: lowercase; ) p:first-letter ( text-transform: uppercase; )

THIS IS AN EXAMPLE SENTENCE.

THIS IS ANOTHER EXAMPLE SENTENCE. AND THIS IS ANOTHER, BUT IT WILL BE ENTIRELY LOWERCASE.

How to convert the letter UPPERCASE to lowercase and the first letter of Uppercase for each sentence as shown below using CSS only?

From: THIS IS AN EXAMPLE APPLICATION.

To: This is an approximate sentence.

Update: When I use text-transform: capize; The result is still the same.

You can't do this solely with CSS. There is a text-transform attribute, but it only accepts none , capitalize uppercase , uppercase , lowercase and inherit .

You might want to look into a JS solution or a server-side solution.

If you can make all characters lowercase on the server, than you can apply:

Text-transform: capitalize

I do not think that text conversion will work with capital letters as input.

If you want to use for this won't work, for or textarea you need to use Javascript

function capitaliseName() ( var str = document.getElementById("name").value; document.getElementById("name").value = str.charAt(0).toUpperCase() + str.slice(1); )

which should work well for or

For several lessons now we've been getting more sophisticated with formatting text using CSS, and this time we're learning how to change the case of text. In this regard, cascading style sheets open up very wide possibilities for us, and to be more precise, we can:

  • Display all text in capital letters;
  • Select all text in lowercase letters;
  • Make sure that the first letter of each word starts with uppercase.

“This is all good, of course, but when might it be needed?” - you ask. Let's imagine a situation where you need to display all menu items in capital letters. To do this, it is not necessary to type them, including the CapsLock key, or while holding down the Shift button. It will be enough to set all list items to display in upper case by creating a corresponding rule in the CSS file. And this is just one of many possible situations.

text-transform property

We will control the case of the text using the text-transform property. It has 4 main values ​​- uppercase (capital letters), lowercase (lowercase letters), capitalize (upper case for each first letter of the word, other values ​​​​do not change), none (formatting is not applied). At first glance, all this may seem very complicated to you.


The main thing is not to panic...

But in practice everything is quite simple, as you will now see. The main thing is to choose the right selector, because the values ​​of the text-transform property are inherited.

Capitalize

First of all, I suggest setting all text to capital letters, for which we create the following CSS rule:

Body ( text-transform: uppercase; )

In principle, nothing complicated, we just used the uppercase value. As they say, everything is intuitive. This is what it looks like in real life:


All with a capital letter... Lower case - apply to all

The next step is to apply lowercase letters everywhere by writing the following:

Body ( text-transform: lowercase; )

As you probably already guessed, the two meanings we just met are to some extent antonyms. And in the illustration below you can see the result of the newly created property.


Web page with lowercase enabled We highlight the first letter of each word in uppercase

To do this, we just need to use the corresponding value:

Body ( text-transform: capitalize; )

I don’t know how often you will use such a CSS rule, but it won’t hurt you to know about such a possibility, especially when solving non-trivial problems. The result can be seen in the image below.


Text after applying capitalize

Finally, let's take a quick look at the last value - none. As I already said, it can be used to cancel inheritance from a parent. For example, let’s imagine that we have all the previous rules in effect, and for paragraphs we should cancel them, for this we write the following:

P (text-transform: none; )

I dare to assume that everything is clear to you, if not, ask your questions in the comments. And that's all for me. I hope this CSS tutorial was helpful to you. If it is true:

  • Repost this article on in social networks, to more people benefited from it;
  • Subscribe to my newsletter so as not to miss useful and interesting blog posts.

This is where I don’t say goodbye to you. Thank you for your attention and see you in the next publications!

HTML Tags and - Subscript and Superscript Text Definition and Usage

The tag defines subscript text. Sublinear text is half the height and appears below the baseline. Interlinear text can be used when writing chemical formulas, such as H 2 O.

The tag specifies superscript text. Superscript text is half the height and appears above the baseline. Superscript text can be used when writing footnotes, such as WWW.

Browser support

Tags are supported by all major browsers.

Differences Between HTML and XHTML Standard Attributes

The DTD column indicates in which document type the HTML 4.01/XHTML 1.0 DTD attribute is allowed. S=Strict, T=Transitional and F=Frameset.

Tags support the following standard attributes:

Attribute Value Description DTD
class class_name Specifies the class name for the element STF
dir rtl
ltr
Specifies the text direction for content in an element STF
id identifier Specifies a unique identifier for an element STF
lang language_code Specifies the language code for the element's content STF
style style_definition Specifies an inline style for an element STF
title text Indicates Additional information about the element STF
xml:lang language_code Defines the language code for element content in XHTML documents STF

More information about Standard Attributes.

Event Attributes

Tags and support the following event attributes:

Attribute Value Description DTD
onclick script Script launched on mouse click STF
ondblclick script Script launched when double click mouse STF
onmousedown script Script to run when mouse button is pressed STF
onmousemove script Script to run when the mouse pointer moves STF
onmouseout script Script to run when the mouse pointer moves outside of an element STF
onmouseover script Script run when the mouse pointer moves over an element STF
onmouseup script Script to run when mouse button is released STF
onkeydown script Script run on keypress STF
onkeypress script Script run when a key is pressed and then released STF
onkeyup script Script to run when the key is released STF

More information about

Hello. Sometimes when creating web pages it is necessary to specify some words with using css uppercase or superscript. Let's see how it's done.

Upper and lower case using css

In general, today you can enclose the desired text in tags and get desired display but let's also see how this can be done using css because the technique is a little different.

For example, you need to write the formula H 2 O in an html document. This is done like this:

  • The formula itself is written
  • Those words and numbers that need to be displayed in upper or lower index are enclosed in a span tag, which needs to be assigned some class. For example: characters to be output
  • In css you need to set this element:

    Top-index(
    Vertical-align: super;
    }

This property is responsible for vertical alignment text. Its value super specifies that the text will be displayed in superscript. But the font size remained the same as regular text. To make everything look nicer, you should also set the font size a little smaller using the font-size property.

This is how the property simply works. Accordingly, to output in subscript you need to write like this:

Top-index(
Vertical-align: sub;
}

The difference from similar HTML tags is that these rules do not change the font size, so if you need to do this, you will have to write a new size in the style sheet.

That's all you need to know about superscript and subscript in css. None additional features the property does not provide, and they are not needed. If you wish, you can design this text in a special way, but this is rarely necessary.

Where it might come in handy

Superscript and subscript text can be used when writing formulas, adding notes and notes to articles. For example, Wikipedia provides sources and notes for each article. As the article progresses, they are placed in the form of small superscripts. This does not irritate readers and at the same time allows you to give the articles the desired look.

The property is fully cross-browser and supported in all versions of CSS.