kerstin
kerstin

Reputation: 1

variable or tag

hello I never understand the difference between a variable and a tag. Can anybody help me? Is there one at all and how bad is it if you mix them up?

Upvotes: 0

Views: 245

Answers (1)

deceze
deceze

Reputation: 522500

An example of tags would be all the <bracketed> things in this HTML snippet:

<p>This is a sentence with <em>tags</em>. Tags add <b>meaning</b> to text.</p>

The tags add meaning to the text ("this is a <p>aragraph", "this should be <em>phasized", "this should be <b>old"). Any consumer (any program or human reading this text) may do with it what he likes. A web browser would choose to render the text like so:

This is a sentence with tags. Tags add meaning to text.

Other consumers may display the text as-is including the tags, or may discard the tags. Tags that do not exist as part of an agreed standard are ignored. As such tags can't be declared, they're just used.

Variables are a mathematical thing and do not exist in HTML. HTML is a passive markup language. Variables OTOH are used in calculations and computations:

var a = 5;
var b = 10;
var c = a + b;
b = 42;

a, b and c are variables that hold values. Variables are declared into existence (var a), they do not exist before you declare that you want to use them and their names are completely arbitrary (as opposed to HTML tags, which are agreed upon in advance in the HTML spec). Their value varies (e.g. the value of b changes from 10 to 42), hence "variables".


CSS is sort of a mix. In CSS, you can declare styles:

.foobar {
    text-size: 200%;
}

This says that any HTML element (tag) with the class "foobar" should have a text size of 200%. This is declared arbitrarily, i.e. you can choose any name for .foobar and add new styles at any time. There aren't any variables in standard CSS though.

Hope that helps.

Upvotes: 2

Related Questions