How to use a span tag or span class in HTML to change text
Hi there this video we are going to make this part of the single line bold by leaving this not bold using something called a span tag. Okay. It looks like that. We're using a span class in this case it just wraps around just the words that we want to change. It doesn't break onto two lines and you style it in your CSS. Let's jump in, work out how to do it and then why we'd want to do it. Plus if you've already done a span tag, you're like don't need this one flip to the end of this video. I've got like a secret extra little bit that we're going to do in terms of changing our preferences. Little tasty treat at the end. Alright, let's get started. Okay, so let's talk about word wrap. I want to wrap just around this line here. Okay, well just these words here, so let's figure out how to do it. There's kind of two ways. So depending on your research project, depends if you've got Yeah, it depends who you got. I'm going to show you both ways so first of all find the text Okay here And we ne...
ed to wrap it up in a span tag. Okay? So I'm going to use my sweet command shift P. Or control shift P. Okay. And I'm going to type in rap wrap even so we're gonna wrap without abbreviation and we're gonna type in span. So either side of it needs span S. P. A N. It's my accent so you don't have to wrap it. You can just type it in either side. Now. You've got two ways of implementing it. You've got kind of straight up in line CSS or you can do what's called a span class. So we'll do the straight up CSS straight in here. And what you do is you style it. Okay. And you start doing, what is that font? Wait and you do, it's called in line CSS. Okay. We're going to go to our bold and that hopefully should do it. Let's have a little look. Refresh. My review is not working. Go live now. It's working awesome. Alright, so old version, I'm not sure why that died. But anyway, we're back and that has made it bold. Okay. And that is perfectly fine job done. If you did it that way we're in business. The only trouble with this way is let's say we also want to color it. If you want to change the colors, you're gonna put in a semi colon, you type in color like we normally do colon and I'm going to pick a random color. Forest green, save it. Let's have a little look and its forest green. Okay. And let's say we also want to do something else and you can see how ugly is not the word, it's ugly as the word. It just gets long and there's so much going on here. This should be over here in our CSS. Okay. So the other problem is it's not reusable. So I want to do this again. Okay. I want to wrap something else. I'm gonna have to grab that bit. Okay. And let's say I want to do it to this last word in our first tab here. Okay. So I wrapped the beginning there. Okay. And it's given me automatically my span and the end closing of the spans opens up says all our stuff. There's our word closes with a slash span and it works okay. But I've got it twice and it's starting to get big and heavy. Ok. So essentially nothing wrong with that. But let's show you a classier way to do it. That's a good word. Classy because it's class. See what I did there. All right. We're going to give this class a name. We're gonna call this one bold. Okay. And over here let's style it where maybe just before the tablet starts. Okay. So at the end of my global, so this one's gonna be called bold. You can kind of see the the niceness of this. So what is that font weight. Okay. And we're gonna pick and that's just a classier way. You can't use the joke twice then come on. Just a nicer way of applying it. Okay. Instead of in line it is this and the cool thing about it is it's reusable. Okay, Because we could call this bold and we could call this one like highlight. Okay. Okay. Then we get to add a bunch of stuff to it high light and then we could say all right, it's going to be a color of random color. What's today? Medium purple, You know? And we can do font size. You get what I mean? Right. 20 pixels just for giggles. So this is quite nice. It's a bit heavier over here. Let's have a little look at how it's doing. Okay. But I can reuse that as well so I can say down here. You are also going to be a span tag of who random shortcuts. What did I do? There we go. You are going to have my command shift. P control shift P. You're gonna have a span tag and you're going to have a span class of what was it called, highlight highlight. All right. Let's have a little look. There we go. Alright, I'm going to switch it back to bold and one thing we'll do before we go. A little a little tasty treat at the end of this video. I'm going to show you something cool. So let me just get this back to I'm gonna leave it as highlight. But okay. And just get rid of this. How does it look now? Perfect. The last one's bold. I'm okay with that. But that was the thing I wanted to do. All right. One thing before we go is explain why we're not doing it in like say two separate div classes or P tags. Let's just have a little look, I'm going to close down the styles for the moment just to show you what it looks like. So I'm going to duplicate it. I'm clicking anywhere in the div and I'm using its option shift down arrow on a Mac. And that will be able to shift down arrow on a Pc. Okay. And I'll look at doing it this way. We'll separate them out so you can see. So let's say we get rid of our span class and we're gonna do it a slightly different way and and I'll pretend that I only want to like the word daniel. Okay, on make a bowl of just daniel. So what I could do is I could create. So I've got a div tag for logo. I could make P two P tags. Right? I'm gonna wrap that in a P tag, nope wrong one. Let's go commercial p wrap with abbreviation P tag. Great. So alright, that's kind of nice ish. Okay, so I'm gonna wrap that up. The first big problem is even though it's on the same line because a P tag is a block level tag, even though it's on its own line. Okay, let's wrap this in a different P tag. P let's go wrapping tag previous. Previous. Let's tidy that up now when I'm moving around in these big chunks, some on a Mac. I don't know if this is true on a pc. It probably is. I had done the option key and use my left and right arrow. That's how I kind of jump across these lines on a pc. Give it a try. It might be all that's left and right arrow. And if I hold down the shift key at the same time, so my MAC its option shift, it kind of selects that big jump so I can kind of hold option and shift and click my left arrow and you can see it just kind of highlights all of that. Alright, that wasn't what I'm telling you. But these are two separate P tex and now I get to style this with a class of highlight. Okay, highlight. Okay. And it'll work kind of except now and here. Oh, there's my second one there it is on two separate lines. Okay, so I wanted to be on one line and a span tag does that is in line not block. So I could now go and find my P tag and say if it's the P tag inside of logo display in line. Okay. Online block So that it doesn't drop on to own its own lines and that would work. My problem with it though, is that google, its search engine will see that as a separate bit of content from this. So let's say we did it for logo. So logo was bold but this wasn't that end up on two separate lines and google would not connected to easily. Okay. It doesn't know you're all about logo design, it knows you're all about logo design. So the two separate kind of parts to the page. So I like to make sure like especially for things like H ones and headings very often I want them on two lines and I want to do some different styling to those two lines just because I'm a designer and unfortunately separating with P tags or two H ones, it's going to break up the content so that it might not string together for the search engine and this is just a little nicer. Right? Alright, goodbye you. Let's close it all up. Oh, I promised a little treat at the end. Cool. So I'm gonna open up my styles double click it, drag it over here. Okay, Every time I close down V. S. Code to go have lunch or go to sleep, okay, I'll wake back up and I have to do this. You've noticed it before we have to go to view were like would wrap again, there's a shortcut but imagine if we just turn it on forever. So I'm going to show you some parts of going through and editing this thing and changing the preferences. It's kind of weird compared to other programs. So what you do is you go to view command palette, we've been using our shortcut. Command shift P on a Mac. It's control shift P on a Pc and you end up with this and we've been using it to do em it wraps. What we want to do is go to settings. Okay. And out of all of these, we want to go to this one that says user settings. Let's open that up. And in here it's worth taking some time to go. Have a little look through things that you were like, oh I'd like to change this. The one that I want is word wrap. So this little search box up here is searching the settings and I can say rep okay. And there's word wrap and controls. It's off by default. We're gonna turn it on by default and we can turn it off if we don't need to. There's also the other fun stuff in there. But that's the one I want at the moment it's closed down settings And now every time I open it up for the rest of this course it's gonna word wrap hopefully. Alright. That is it span tax. We did span in line CSS. Okay, so just a span tag and now we've done a span class. If you did something slightly different. How else could you have done it? If you did something else different and it works? Send me a screenshot of the code that you made it work. Okay put it in the comments or tag me on social media. I'd be interested to see what other ways you creative ways you made it work. Alright. That is it for spent tanks