Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what benefits are there to using a span instead of input

I've noticed on a couple of websites such as Facebook, and Twitter that instead of using regular <input> fields in their markup, they use a <span> and append what the user types onto it using JavaScript.

This process is used both, when a user sends direct messages to other users, when a user posts, and when a comment is made on a post.

I can't think of any possible reason as to why this would be beneficial to use over the HTML5 native <input> tag..

So what are the benefits of using this method? And if there aren't any, why are they doing it?

like image 940
GROVER. Avatar asked Dec 22 '16 00:12

GROVER.


People also ask

What is span used for?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.

Why do we use span in HTML?

<span>: The Content Span element The <span> HTML element is a generic inline container for phrasing content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang .

What is the benefit of using the label element as opposed to a span or plain text?

The <label> tag defines a label for an element. The <label> element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the <label> element, it toggles the control.

What is the use of SPAN tag give an example?

The span tag is used for the grouping of inline elements & this tag does not make any visual change by itself. span is very similar to the div tag, but div is a block-level tag and span is an inline tag. Example 1: In this example, we simply use span tag with style in HTML.


1 Answers

A standard input element is limited to plain text input. This works fine for most situations where you are looking for input from the user.

However, both Facebook and Twitter offer something that goes beyond plain text:

Composing example tweet

As you can see, there is more to it than just plain text: Formatting. Both Facebook and Twitter support inline formatting for special things like mentions and hash tags. In order to format these in a different style, they cannot use an input element but have to render the content differently.

Instead, they use a content-editable element to allow users to input content while still supporting full formatting capabilities.

Note that while contenteditable offers many ways to format stuff, it can also be a nightmare if you’re building something more complex. Medium, who do offer a very powerful and useful text editor, has written about that topic before, about how they built their editor, what problems they encountered, and how they tried to get around it.

like image 140
poke Avatar answered Oct 09 '22 11:10

poke