Hot answers tagged

664

Update: this answer seems to be pretty popular so I took some time to clean it up a little bit, add some new info and clarify few things that I thought were not clear enough. Please comment if you think anything else needs clarification or updates. Most of your concerns are really a matter of opinion and personal preference but I'll try to answer as ...


348

This is a fascinating question. The other answers here are all speculative, and in some cases flat-out incorrect. Instead of writing my opinion here, I actually did some research and found original sources that discuss why delete and put are not part of the HTML5 form standard. As it turns out, these methods were included in several, early HTML5 drafts (!), ...


153

The question is if the data is semantically a table (i.e. a set of data or units of information logically organized in two dimensions) or you just use the grid for visual layout, e.g. because you want a sidebar to expand or something like that. If your information is semantically a table, you use a <table>-tag. If you just want a grid for layout ...


140

Specification says UNIQUE HTML 4.01 specification says ID must be document-wide unique. HTML 5 specification says the same thing but in other words. It says that ID must be unique in its home subtree, which is basically the document if we read the definition of it. Avoid duplication But since HTML renderers are very forgiving when it comes to ...


135

Last summer, I read the complete HTML5 specification, and every previous HTML specification (even the abandoned ones), and all CSS specs I could find, and a lot of XML specs. Since I love semantically rich hypertext documents, let me give you the idea behind the relevant HTML semantics in HTML5. Before HTML5 Before HTML5, i and b were indeed out of fashion....


120

This is a common pattern for making responsive tables. Tabular data is tricky to display on mobiles since the page will either be zoomed in to read text, meaning tables go off the side of the page and the user has to scroll backwards and forwards to read the table, or the page will be zoomed out, usually meaning that the table is too small to be able to read....


102

Actually, I would say that the use of class names like "table" in your example demonstrates how people don't actually understand what they're doing when trying for semantic markup. They get marks for trying to show that the content is not tabular data, but they lose marks for bad class names. <div class="table"> <div class="row"> <div ...


101

Free Functionality Properly using <label>s means you can click the label to enter the text field. Many browsers will add logical default functionality to many tags per the official specification, meaning you can use fewer JavaScript plugins and write less code than a site made entirely out of <div>s and <span>s. Accessibility Related to ...


87

HTML and CSS are difficult to interview for a few reasons: They are too basic, compared, for example, to a programming language, They depend very much on the context of the job. Examples: If you create Google scale, hugely fast and optimized websites, the people you interview for the job cannot ignore what CSS sprites are. If you create XHTML W3C valid ...


87

If you don't know whether you need server-side code, you probably don’t* *Caveat: Server-side code is essential for security, when you want to internally control access to content, data, or functionality. (It does not necessarily need to be your server, see last paragraph.) Ask yourself what problem using server-side technologies would solve. If you can’t ...


82

You should build a house first, then paint it. An HTML document can stand on its own, even though it may look dull. A CSS style sheet cannot; it is nothing displayable (except as code) but instructions for display. It’s a different issue that during painting, you may wish to do changes to the house. With real houses that’s usually not feasible, but in HTML+...


79

I believe you are looking at the problem the wrong way - you are missing a great opportunity of teaching the juniors how to write better code. If you habitually re-write their code, you might give your juniors the impression that you don't value their work, which will lower their morale, and not help them code better the next time. A better approach, I ...


58

As Doval says, they are not deprecated. They still exist but should be used differently from what many people where used to before HTML5. It's about 'semantic' html. It should describe 'what' it is, instead of how it should look. The browser or theoretically any other display medium (say a reading app for the blind) should be able to decide how exactly ...


56

Read about static site generators. These allow you to create a site in a programmatic manner (using templates, data, etc), and not by hand-crafting HTML. The result is a set of static HTML and CSS that does not require any backend. https://www.staticgen.com/ lists and ranks a number of such open-source generators; closed-source offerings likely exist, too.


54

To directly answer your question: Never echo static text or HTML. Leave that outside of your PHP. <?php echo "<p>Hello World</p>"; // Alway wrong. ?> <p>Hello World</p> <!-- Does the same thing, faster, and is more readable. --> Escaping to PHP is a waste if all you are going to do is pass in static text or static html....


50

No, this is not a good practice. You should use already semantic, meaningful tags -- perhaps <em> in this case -- and apply CSS styles to achieve your design requirements.


41

The true story is that b and i were first obsoleted, deprecated, cursed, and anatematized as “presentational” in various HTML5 drafts (broadly speaking), but then they realized that these tags are widely used and also generated by many authoring programs. Instead of simply allowing them, they developed contrived new “semantic” definitions for them, to be ...


39

The reason is simple: At the time of the first graphical browsers, NCSA Mosiac and later Netscape Navigator, almost all HTML was written by hand. The browser authors (Netscape was built by ex-Mosaic folks) recognized quickly that refusing to render incorrect HTML would be held against them by the users, and voila!


35

You don't have to learn JavaScript and HTML to create web applications. But you will. If you really want to write webapps in mostly Java, have a look at the Google Web Toolkit, which does vast amounts of Java to JS, and can satisfy a good chunk of the code needed for a webapp. Django is a similar framework for Python. And if you really want to avoid ...


35

Because making best guesses is the right thing to do, from a browser-maker's perspective. Consider the situation: ideally, the HTML you receive is completely correct and to spec. That's great. But the interesting part is what happens when the HTML is not correct; since we're dealing with input from a source that we have no influence on, really, we have to be ...


35

There is no way to avoid that. They are coupled because they interact with each other. If your javascript intends on doing any kind of DOM manipulation, then it needs a way to reference the DOM. There are various conventions for it. The Level 2 DOM API provides the getElementById, getElementByTagName, and getElementsByName methods. To this day these are ...


35

You literally cannot prevent users from accessing and modifying content that you are sending them. You have no control over the browser, or which browser they use, or whether they are in fact downloading your source code via a browser. You are executing your code on another person's device. You should not and cannot assume anything about the integrity of ...


31

I have used this technique exclusively for a web application we're working on. My backend is hosted on Google App Engine using the Java SDK, and my frontend uses HTML, CSS, and JavaScript (with jQuery). The project is a smaller one with just myself and a Web designer, and we both feel that this method has helped us work a lot faster and get something to ...


31

If you don't use cookies at all then it would be a huge misinformation to warn your visitors about using cookies. It may even be useful to explicitly state that you don't use cookies. Remember that warnings about cookies are for people who want to avoid cookies so they should know when they finally get to a rare website that doesn't use them. But you may ...


30

Not anytime soon. The era of WYSIWYG editors is long over (like the dinosaurs) but companies continue to pump it out. I remember the days of using Dreamweaver and having dozens of spacer.gif images to put the layout in the same way. Software like this is fool's gold - it's meant to appeal to people who want something quick and dirty (tomorrow as opposed ...


30

You asked "how bad". So to flesh out @RobertKoritnik's (entirely accurate) answer a bit... That code is incorrect. Incorrect doesn't come in shades of grey. This code violates the standard and is therefore incorrect. It would fail validation checking, and it should. That said, no browser currently on the market would complain about it, or have any problem ...


30

Today, in our work as in our life, it is more important know how to find information rather than know the information itself. I mean that a good developer is a person able to find documentation, network, and that share with an open mind. I am an experienced .NET developer and, believe me, for every project I work on I have to learn new things about the ...


29

I think the problem is that you are comparing cleanly written server side templating to badly written ad-hoc client side HTML generation. Of course the cleanly written code is easier to read, maintain, and trace. You call the client side code "mounds of HTML", but of course it's the same HTML wherever it's generated. The "mound" is really the big lump ...


29

Former Designer here, turned Dev, and I used to piss and moan about Web Controls too. Honestly, its MUCH cheaper for a designer to adjust their practices than for a .NET Developer to delve into a custom impelmentation of a GridView because the designer INSISTED that each TD have a 'rel' tag (or whatever). As Arseni Mourzenko very wisely pointed out, the ...


Only top voted, non community-wiki answers of a minimum length are eligible