-3

I have used HTML in its basic form, and I mainly work on "server side" (of Enterprise application, mainly based in Java EE).

From what I understand, HTML is the "pages" which we see in an browser (that source code which a GUI developer writes and which a browser renders appropriately).

For example in an HTML tag, we write "h1" element, and the browser displays the text within as bold.

Now why there is any need of css? From what I am aware of, CSS is used to give "style" to a html page. The confusion that I have, doesn't HTML in itself able to give the style? what were the compelling reasons for creation of css?

Can anyone help me understand this in simple words.

CuriousMind
  • 8,301
  • 22
  • 65
  • 134
  • Those who are downgrading can you please give reason why? – CuriousMind Aug 06 '16 at 08:58
  • The thing you're describing is usually called *"inline styles"*. If you want to know why it's discouraged in favour of putting the styles in CSS, there's plenty of material out there explaining this. For example: http://stackoverflow.com/q/2612483/3001761 – jonrsharpe Aug 06 '16 at 09:00
  • 1
    The bold appearance the browser applies to an `h1` element is the result of the default css rules the browsers use. HTML used to carry some styling informations like `border` or `align` attributes, but since html5 you should use html only for the semantic information. – t.niese Aug 06 '16 at 09:02
  • 1
    The style you see in a browser if you do _not_ provide any style rules (css) simply is the _default rules_ implemented in a browser. Displaying html without any style would look like plain text without any styling at all. Not good. Think of it as this: html is the "what", css is the "how". – arkascha Aug 06 '16 at 09:05
  • @t.niese: Thanks for the info. When i initially used it, there was no CSS what I am aware of. My doubt is when html does some style of its own, what was the need of css? – CuriousMind Aug 06 '16 at 09:05
  • 1
    @CuriousMind you are on a website right now which is styled with CSS. Without CSS the page we are on right now would look like this: http://i.imgur.com/fcBwD0b.png I think you'll agree that there are pretty clear benefits to using CSS to control the presentation of the page. Bear in mind that when you use style="" to apply styles to an item in an HTML document that is also CSS. – JBartus Aug 06 '16 at 09:16
  • 1
    HTML does not "do some style of its own". HTML is strictly passive. It _does_ mark parts of content in a semantic way, but it does _not_ apply any rules as to _how_ that part is to be displayed. A common miss conception. – arkascha Aug 06 '16 at 09:17
  • 1
    @CuriousMind Actually the content in the scrreenshot _does_ have style rules applied. – arkascha Aug 06 '16 at 09:17
  • 1
    @arkascha let's not obfuscate the matter by being overly technical, it's clear that their grasp of HTML is rudimentary at best and they repeatedly ask what the need for CSS is which is demonstrated easily by stripping all but the default browser styling (which is CSS yes) from the page for him to see. – JBartus Aug 06 '16 at 09:23
  • 1
    @J.Bartus Not sure, I am a fan of enabling people to _really_ understand the tools they use. I do not really like those approaches to teach people "a bit". Only real understanding enables people to go on themselves. – arkascha Aug 06 '16 at 09:26
  • 1
    @arkascha I agree entirely but when you were a child you learned to walk before you could run, your first bike had training wheels until you learned to balance on your own, etc. Until a basic understanding of the relationship between CSS and HTML is attained the technical detail of browser default CSS styles is immaterial. – JBartus Aug 06 '16 at 09:32
  • I thank you all for your inputs. I did some reading on this, but still I am having doubts, so I decided to ask the question on SO, because we have very talented people in SO and at times do help save time in learning the concepts better. From what I read from wikipedia, HTML came in 1993; and CSS 1996; so in between these three years how does HTML do all this. That was the reason for me asking that html does have tag like "h1" which displays the text in bold. That was the reason I am bit confused between HTML and CSS. Nevertheless I am thankful to you all for your wonderful insights. – CuriousMind Aug 06 '16 at 09:34
  • 1
    @CuriousMind the simplest answer is that there were other forms of style sheets (CSS = Cascading Style Sheets) in use prior to the introduction of CSS dating back to SGML (Standard Generalized Markup Language, sort of an HTML predecessor if you will) back in the 1980s. CSS is a style sheet language developed specifically for use with the web. Documents simply used other style sheet formats until the CSS language / standard was developed and adopted. – JBartus Aug 06 '16 at 09:40
  • 1
    Sure, a valid question, no doubt. But once more: the fact that HTML defines a `h1` tag does _not_ define that this is to be displayed in bold. Not at all. It is up to the visualizing utility to decide or define that. HTML does not define any style rules for such a headline. One could easily imagine a browser for blind people for example that displays headings completely different. And that is a perfectly valid and correct application of HTML. – arkascha Aug 06 '16 at 09:40
  • Thanks all of you for your inputs. Things got better than before. I wish I could take you all for a party. – CuriousMind Aug 06 '16 at 09:44
  • 1
    HTML5 standard only defines the semantic meaning of a html tag, but does not define any style for it. The styling has to be done using CSS. The standard only mentions _Typical default display properties_ (css) that are commonly used as default build in css rules by browser. HTML=Semantic, CSS=Styling. In ancient html3 or html4 you where able to add styling using plain html, but all of these attributes are obsolete for html5 [11 Obsolete features](https://www.w3.org/TR/html5/obsolete.html) instead css has to be used. In favour to have a clear separation of style and information. – t.niese Aug 06 '16 at 10:17

1 Answers1

-1

The code that you put in your html to style it is actually CSS. HTML actually has some built in CSS. So really, you are using CSS when you do that. Also people like to connect a separate file for CSS in bigger projects. It looks more organized, and it easier to keep track of. It is also easier to code the CSS, because it is less messy and it seems like you have a bit more functionality. In conclusion, the code in the html that you are using to style with, is actually CSS, just built in. Also, I would highly recommend separating your stylesheet and HTML file(the stylesheet is CSS). If you need help, go to codecademy and create an account. Take the HTML and CSS lesson. I found this very useful and is where I learned most of my knowledge. I would highly recommend going to that site also. The site is also free.

Dallas White
  • 83
  • 1
  • 10
  • 2
    Emmm... HTML does not have "some built in CSS". You can note inline style rules, yes. But they are style rules, not "cascading style sheets". – arkascha Aug 06 '16 at 09:21
  • 2
    I guess you mean that browsers apply some basic style rules to elements. – redelschaap Aug 06 '16 at 09:30
  • 6
    No offense, @Dallas White, but if the only credit to your knowledge on the matter is having taken a codecademy course on HTML and CSS then you really don't possess the level of knowledge to be trying to help people here yet. There are a number of factual inaccuracies in your answer that are, frankly, cringeworthy. Codecademy is a great resource and tool for users just getting their feet wet in coding but it is a far cry from being comprehensive or making you an expert. I do, however, applaud your desire to help! – JBartus Aug 06 '16 at 09:36