23

Has Emmet a syntax for adding URL into <a href=""> tag?

E.g.:

Syntax:

a:www.google.com

Result:

<a href="www.google.com"></a>
Runtime Terror
  • 6,242
  • 11
  • 50
  • 90

3 Answers3

25

The general syntax for adding an attribute to an element in Emmet is:

element[attr=value]

So in this case, it'd be:

a[href=www.google.com]

That said, if you just do a by itself, it should automatically jump the editor cursor into the href attribute, and you can do a:link to pre-populate it with a http://. So those options might be faster/more to your tastes.

For more information, look at the Emmet Cheat Sheet - it lists all the syntax that's available.

Joe Clay
  • 33,401
  • 4
  • 85
  • 85
  • How would I add the content of the element into the href? For example, `https://google.com` So when I wrap the link https://google.com it gets place in the href. I know it will do it when using only `a` by itself, but I want to create a custom anchor tag such as: `a[href=\"{whatever the value is}\" target=\"_blank\" rel=\"noopener\"]` I am wrapping a lot of links and therefore need a way to do this more efficiently. Thanks. – Henry Jun 08 '23 at 15:06
16

Slightly shorter:

a[www.google.com]

equals:

<a href="www.google.com"></a>
Keno
  • 3,694
  • 2
  • 21
  • 40
0

In VSCode you can wrap the text you need to link and as the link url, use "Wrap with Abbreviation" (Cmd+Shift+P and type Emmet to see shortcuts).

Use this snippet: a[href="$#"] The content will be interpolated as the link URL.

From http://www.example.com to <a href="http://www.example.com">http://www.example.com</a>

SigBaldi
  • 1
  • 2