- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do we do variable formatting using the tag in HTML?
We use <var> tag to define a variable in programming or in a mathematical expression. It is also used to format text in a document. The content inside this tag is typically displayed in italic font.
Syntax
<var>Variable…</var>
Example 1
Following is an example to perform 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>
Example 2
You can try to run the following code to do variable formatting using the <var> tag in HTML −
<!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>
Example 3
We can override the font style using style sheet. The example 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>
Advertisements
To Continue Learning Please Login
Login with Google