Home > Web Front-end > HTML Tutorial > How can we use tag for variable formatting in HTML?

How can we use tag for variable formatting in HTML?

WBOY
Release: 2023-08-25 21:21:11
forward
1498 people have browsed it

How can we use <var> tag for variable formatting in HTML?

We use the tag to define variables in programming or mathematical expressions. It is also used to format text in documents. Content within this tag is usually shown in italics.

grammar

<var>Variable…</var>
Copy after login

Example 1

The following is an example of performing variable formatting using the tag in HTML -

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <meta name="description" content="meta tag in the web document">
   <meta name="keywords" content="HTML,CSS">
   <meta name="author" content="lokesh">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
   <p>
      <var>a</var> = float(input('Enter a value: ')) <br>
      <var>b </var>= float(input('Enter b value: ')) <br>
      <var>c </var>= float(input('Enter c value: ')) <br>
      # calculate the semi-perimeter <br>
      <var>s </var>= (<var>a</var> +<var> b</var> +<var> c</var>) / 2 <br>
      # calculate the area <br>
      area = (<var>s</var>*(<var>s</var>-<var>a</var>)*(<var>s</var>-<var>b</var>)*(<var>s</var>-<var>c</var>)) ** 0.5 <br>
      print('The area of the triangle is %0.2<var>f</var>' %area)
   </p>
</body>
</html>
Copy after login
The Chinese translation of

Example 2

is:

Example 2

You can try running the following code to use the tag in HTML for variable formatting -

<!DOCTYPE html>
<html>
<head>
   <title>HTML var Tag</title>
</head>
<body>
   <p>The equations: <var>2x</var> - <var>3z
      </var> = <var>5y</var> + 2 and
      <var>2x</var> + <var>5z</var> = <var>2y</var> + 7
   </p>
</body>
</html>
Copy after login

Example 3

is translated as:

Example 3

We can override font styles using style sheets. The sample code is as follows:

<!DOCTYPE html>
<html>
<head>
   <meta charset="UTF-8">
   <meta name="description" content="meta tag in the web document">
   <meta name="keywords" content="HTML,CSS">
   <meta name="author" content="lokesh">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <style>
      var{
         font-family: cursive;
      }
   </style>
</head>
<body>
   <p>
      <var>a</var> = float(input('Enter a value: ')) <br>
      <var>b </var>= float(input('Enter b value: ')) <br>
      <var>c </var>= float(input('Enter c value: ')) <br>
      # calculate the semi-perimeter <br>
      <var>s </var>= (<var>a</var> +<var> b</var> +<var> c</var>) / 2 <br>
      # calculate the area <br>
      area = (<var>s</var>*(<var>s</var>-<var>a</var>)*(<var>s</var>-<var>b</var>)*(<var>s</var>-<var>c</var>)) ** 0.5 <br>
      print('The area of the triangle is %0.2<var>f</var>' %area)
   </p>
</body>
</html>
Copy after login

The above is the detailed content of How can we use tag for variable formatting in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template